package com.taoxi.good.controller;

import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.core.page.TableDataInfo;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.good.domain.GoodImg;
import com.taoxi.good.service.IGoodImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品图片Controller
 *
 * @author ruoyi
 * @date 2024-10-21
 */
@Api(tags = "商品图片Controller")
@RestController
@RequestMapping("/good/img")
public class GoodImgController extends BaseController {
    @Autowired
    private IGoodImgService goodImgService;

    /**
     * 查询商品图片列表
     */
    @ApiOperation("查询商品图片列表")
    @PreAuthorize("@ss.hasPermi('good:img:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodImg goodImg) {
        startPage();
        List<GoodImg> list = goodImgService.selectGoodImgList(goodImg);
        return getDataTable(list);
    }

    /**
     * 导出商品图片列表
     */
    @ApiOperation("导出商品图片列表")
    @PreAuthorize("@ss.hasPermi('good:img:export')")
    @Log(title = "商品图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodImg goodImg) {
        List<GoodImg> list = goodImgService.selectGoodImgList(goodImg);
        ExcelUtil<GoodImg> util = new ExcelUtil<GoodImg>(GoodImg.class);
        util.exportExcel(response, list, "商品图片数据");
    }

    /**
     * 获取商品图片详细信息
     */
    @ApiOperation("获取商品图片详细信息")
    @PreAuthorize("@ss.hasPermi('good:img:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(goodImgService.selectGoodImgById(id));
    }

    /**
     * 新增商品图片
     */
    @ApiOperation("新增商品图片")
    @PreAuthorize("@ss.hasPermi('good:img:add')")
    @Log(title = "商品图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodImg goodImg) {
        return toAjax(goodImgService.insertGoodImg(goodImg));
    }

    /**
     * 修改商品图片
     */
    @ApiOperation("修改商品图片")
    @PreAuthorize("@ss.hasPermi('good:img:edit')")
    @Log(title = "商品图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodImg goodImg) {
        return toAjax(goodImgService.updateGoodImg(goodImg));
    }

    /**
     * 删除商品图片
     */
    @ApiOperation("删除商品图片")
    @PreAuthorize("@ss.hasPermi('good:img:remove')")
    @Log(title = "商品图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(goodImgService.deleteGoodImgByIds(ids));
    }
}
